﻿var check = null;
if (window.parent.window != window) {
    window.top.location.href = "/Login/Index";
}
$(function () {
    //实现用户的登录信息
    LoginUserInfo();
    //$("#jizhu").change(function () {
    //    check = $(this).attr("checked");
    //    check =   $(this).is(':checked');
    //      alert(check);
    //})
    //单击重新改变验证码
    //ClickRemoveChangeCode();
});
//异步实现用户的登录
function LoginUserInfo(LoginUserInfo) {
    $("#btnLogin").click(function () {
        //验证用户必须输入必填项
        var validate = IsValid();// $("#mail").form("validate");
        if (validate == false) {
            return false;
        }
        $("#btnLogin").hide();
        //获取传递前台的参数，Phone，Pwd，Code
        //if (typeof check == 'undefined') check = null;
        var postData = {
            Phone: encodeURIComponent($("#Phone").val()),
            Pwd: encodeURIComponent($("#Pwd").val()),
            jizhu: $("#jizhu").is(':checked'),
            __RequestVerificationToken: $("input[name='__RequestVerificationToken']").val(),
            newid: Math.random()
        };
        //异步实现登录功能
        $.post("/Login/CheckUserLogin", postData, function (data, textStatus) {
            //alert(textStatus);
            if (data == "OK") {
                window.location.href = "/Home/Index";
                //$("#btnLogin").show();
            } else if ("Reset" == data) {
                alert("您的密码过于简单，请修改密码！");
                window.location.href = "/yonghu/pwd1";
                $("#btnLogin").show();
            }
            else {
                //alert(data);
                //window.location.href = "/Login/Index/";
                $("#Pwd").val("");
                $("#div_error").html(data);
                $("#btnLogin").show();
            }
            if (textStatus != "success") {
                $("#btnLogin").show();
            }
        });
    });
}
//删除cookies
function delCookie(name) {
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval = getCookie(name);
    if (cval != null) document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
}


getValue = function getvalue(name) {
    var str = window.location.search.substring(1);
    var params = str.split('&');
    var val = -1;
    for (var i = 0; i < params.length; i++) {
        if (params[i].indexOf('=') != -1) {
            var param = params[i].split('=');

            if (param.length == 2) {
                if (param[0].toLowerCase() == name.toLowerCase()) {
                    val = param[1];
                }
            }
        }
    }
    return val;
};
$(document).ready(function () {
    if (getValue('errorMessage') != -1) {
        var errorMessage = decodeURIComponent(getValue('errorMessage'));
        alert(errorMessage);
        $("#div_error").text('提示：' + errorMessage);

    } else {
        $("#div_error").text("");
    }
});
//单击重新改变验证码
//function ClickRemoveChangeCode() {
//    var code = $("#imgCode").attr("src");
//    $("#imgCode").attr("src", code + "1");
//}